/**
 * 抖音极速版刷金币新版本
 */

const perVideoWatchTime = 8 // 每个视频观看时长
const halfDeviceHeight = device.height / 2
const halfDeviceWidth = device.width / 2
const videoSwipeDistance = halfDeviceHeight - 100 // 视频下滑的长度 px

auto.waitFor();
app.launchApp('抖音极速版')
sleep(4000);
youngWin();
newVersion()
i = 1;
while (true) {
    WidthOne = random(300, 800);
    HeightOne = random(1600, 1800);
    WidthTwo = random(300, 800);
    HeightTwo = random(500, 700);
    timeGo = random(350, 700);
    timeNext = random(4000, 7000);
    // heartClick();
    randomHeart();
    swipe(WidthOne, HeightOne, WidthTwo, HeightTwo, timeGo);
    toast("滑动" + i + '次，休眠' + timeNext/1000 + "秒")
    sleep(timeNext);
    i++;
}

/**如果弹出青少年窗口，点击 */
function youngWin() {
    if (youngWin = text("我知道了").exists()) {
        youngWin.click();
    };
}

/**随机点赞并休息一秒 */
function heartClick() {
    index = random(1, 5);
    if (index == 3) {
        id('a4o').findOnce().click();
    }
    sleep(1000);
}

//检测到新版本跳过
function newVersion() {
    if (newVersion = text("以后再说").exists()) {
        newVersion.click();
    };
}

/**
 * 自动提交评论
 * content str 评论内容，默认为666
*/
function autoComment() {
    content = '666'
    id('pz').findOnce().click();
    sleep(1000);
    b = id('pz').findOnce().bounds();
    sleep(1000);
    click(b.centerX(), b.centerY());
    sleep(1000);
    setText(content);
    sleep(1000);
    click(b.centerX(), b.centerY());
    sleep(1000);
    click(device.width - 80, b.centerY());
    sleep(1000);
    back();
}



/**
 * 随机点赞
 */
function randomHeart() {
    index = random(1, 5);
    if (index == 3) {
        // let frameLayouts = className("android.widget.FrameLayout").depth(7).selected(false).clickable(true).find();
        // toastLog("FrameLayout" + frameLayouts.length);
        // if (frameLayouts.length == 9) {
        //     frameLayouts[frameLayouts.length - 6].click();
        // }
        toast("点个赞休息1秒")
        id("by8").findOne().click()
        sleep(1000);
    }
}

/**
 * 随机关注
 */
function randomFollow() {
    try {
        index = random(1, 10);
        if (index == 1) {
            let followMes = className("android.widget.Button").desc("关注").find();
            if (followMes.length > 0) {
                followMes[followMes.length - 1].click();
            }
        }
    } catch (error) {
        console.error(error);
    }
}
